package com.maker.LMMS.controller;

import com.blade.mvc.annotation.*;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;
import com.maker.LMMS.service.Md5;
import com.maker.LMMS.service.ShowImpl;
import com.maker.LMMS.service.UserImpl;
import com.maker.LMMS.service.Vcode;

/**
 * @author : zimu
 * @Date: 2018/7/24 09:47
 * @description :  首页请求路由
 */

@Path
public class IndexController {
    @GetRoute("/")
    public String index(Request request){
        ShowImpl show = new ShowImpl();
        show.showIndex(request);
        show.showSomeNewMember(request);
        show.showHeadMan(request);
        return "index";

    }

    @GetRoute("/index.html")
    public void indexhtml(Response response){
        response.redirect("/");
    }
    @GetRoute("/index")
    public void in(Response response){
        response.redirect("/");
    }

    @GetRoute("/signin")
    public String sigin(Request request, Response response) {
        Vcode vcode = new Vcode();
        vcode.doGet(request, response);
        return "signin.html";
    }

    @GetRoute("/signup")
    public String signup(Request request) {
        ShowImpl show = new ShowImpl();
        show.showRegister(request);
        return "signup";
    }

    @GetRoute("/allMember/all/:id")
    public String allMember(Request request,@PathParam Integer id) {
        ShowImpl show = new ShowImpl();
        show.showAllInformation(request);
//        show.showHeadMan(request);
        show.showMembers(request);
        return "allMember";
    }

    @GetRoute("/allMember/period/:id")
    public String periodMember(Request request,@PathParam Integer id) {//id 届别
        ShowImpl show = new ShowImpl();
        show.showPeriodMembers(request,id);
        return "periodMember";
    }

    @GetRoute("/allMember/memberInfor/:id")
    public String memberInfor(Request request,@PathParam Integer id){
        ShowImpl show = new ShowImpl();
        show.showAllInformation(request);
        show.showHeadMan(request);
        show.showMember(request,id);
        return "memberInfor";
    }

    @GetRoute("/bbs")
    public String bbs(){
        return "bbs";
    }


    @GetRoute("/sousuo")
    public String sousuo(){return  "sousuo";}

    @GetRoute("/history")
    public String history(Request request){
        ShowImpl show = new ShowImpl();
        show.showDevlopment(request);
        return  "history";
    }

    @GetRoute("/showinfo")
    public String showinfo(Request request){
        ShowImpl show = new ShowImpl();
        show.showAllInformation(request);
        show.showSomeNewMember(request);
        return "showinfo";
    }


    @GetRoute("/aboutus")
    public String aboutus(Request request){
        ShowImpl show = new ShowImpl();
        show.showAboutus(request);
        return "about-us.html";
    }

    @GetRoute("/updatePassword")
    public String updatePassword(){
        return "updatePassword";
    }

    @GetRoute("/wanshan/:id")
    public String wanshan(Request request,@PathParam int id,@Param int g, Response response){
        ShowImpl show = new ShowImpl();
        if (!show.checkUser(request, id)) {
            response.html("<script>alert('您无权访问此页面');window.location=\"/\";</script>");
            return "/";
        }
        show.showWanshan(request, id);
        request.attribute("g",g);
        return "wanshan";
    }

    @GetRoute("/group")
    public String gro(Request request){
        ShowImpl show = new ShowImpl();
        show.showGroup(request);
        return "group";
    }

    @GetRoute("/news")
    public String news(Request request){
        return "news";
    }

    @GetRoute("/searchResult")
    public String searchResult(){
        return "searchResult";
    }

    @GetRoute("/verification")
    public String verification() {
        return "verification";
    }

    @GetRoute("/forgotPassword")
    public String forgotPassword(Request request, Response response, @Param String email, @Param String code) {
        Md5 md5 = new Md5();
        UserImpl user = new UserImpl();
        if (user.checkCode(request, email, code)) {
            request.attribute("email", email);
            request.attribute("ecode", code);
            return "forgotPassword";
        }
        response.html("<script>alert('此链接已失效~');window.location.href='/';</script>");
        return "index";
    }

    @GetRoute("/admin")
    public void admin(Response response){
        response.redirect("/backstage");
    }

}
